home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: How to convert char to hex in C++?
- Date: Sat, 03 Feb 1996 02:19:00 GMT
- Organization: Netcom
- Message-ID: <3112c479.88246912@nntp.ix.netcom.com>
- References: <DM679K.BD1@undergrad.math.uwaterloo.ca>
- NNTP-Posting-Host: ix-dc14-21.ix.netcom.com
- X-NETCOM-Date: Fri Feb 02 6:19:01 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- hylo@neumann.uwaterloo.ca (Grace Hai Yan Lo) wrote:
-
- > I just wonder if anyone know how to convert a char (e.g. 'a') to
- > hex digit (i.e. 61 for 'a') in C++? Somehow the cout << hex << n <<endl;
- > works for n being an integer but not a character. Thanks.
-
- Make it an int:
-
- cout << hex << int('a') << endl;
-
- In C++ char is an integer in that you can do arithmentic on it and it
- can be converted to other integer types. The conversion to another
- integral type converts the internal representation.
-
- Note that 'a' does not necessarly convert to 61 hex. It does in
- ASCII, but there are other character sets.
-
-
- Michael M Rubenstein
-